#ifndef __SELECTOR_HPP__
#define __SELECTOR_HPP__

#include <netinet/in.h>
/* According to POSIX.1-2001 */
#include <sys/select.h>

#include<sys/socket.h>
#include<pthread.h>
/* According to earlier standards */
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

#include <list>
#include <errno.h>
#include "smartvision.h"
#include "xsocket.h"

using namespace std;

class selector_item {
public:
	XSocket sock;
public:
	selector_item(){
		sock.m_nSock = -1;
	}
	virtual ~selector_item(){};
	
	/* if selector failed , arg0 is less than zero . arg1 is reserved */
	virtual int action( int arg0 , void * arg1 ) { return 0; };
};

class selector {
public:
	struct timespec tvspec;
	fd_set fds;
	list < selector_item * > item_list;
public:
	selector( );
	selector( struct timespec timeout );
	BOOL del_fd( selector_item * item_p );
	BOOL set_fd( selector_item * item_p );
	BOOL set_timeout(struct timespec timeout );
	int select();

	void select_alway( int condition );
};

#endif
